package com.alibaba.discovery.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {
   /* @Autowired
    private LoadBalancerClient loadBalancerClient;*/
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping(value = "/consumer/{string}")
    public String echo(@PathVariable String string) {
       // ServiceInstance serviceInstance = loadBalancerClient.choose("provider-discovery");
        String url = String.format("http://%s:%s/echo/%s","127.0.0.1","8081",string);
        System.out.println("request url:"+url);
        return restTemplate.getForObject(url,String.class);
      /*  return "Hello Nacos Discovery " + string;*/
    }
}
